package com.tianhui.consignortwofei.mvp.ui.activity.hetong;

import android.view.View;

import com.fgs.common.other.CommonEvent;
import com.tianhui.consignortwofei.api.hetong.HuRequest;
import com.tianhui.consignortwofei.mvp.model.DriverModel;
import com.tianhui.consignortwofei.mvp.model.enty.OrderCondition;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.contract.ContractListContract;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.impl.HeTongIOrderStatus;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.presenter.TaiTouPresenter;
import com.tianhui.consignortwofei.mvp.ui.adapter.TaiTouListAdapter;
import com.tianhui.consignortwofei.other.EventWhat;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.inter.OnItemClickListener;

/**
 * @author fgs
 * @date 2020/8/27
 * @description
 **/
public class TaiTouListFragment extends HeTongSearchFragment<ContractListContract.View, ContractListContract.Presenter> implements ContractListContract.View {

    private HeTongIOrderStatus mIOrderStatus;
    private String mSearchKey;
    private String mYinCangWitch="";

//    private ContractModel contractModel;
    private HuRequest huRequest;
    private DriverModel driverModel;

    public TaiTouListFragment() {
        // Required empty public constructor
//        contractModel = new ContractModel();
        driverModel=new DriverModel();
    }

    @Override
    public boolean isNeedLazyLoad() {
        return false;
    }

    public static TaiTouListFragment newInstance(HeTongIOrderStatus iOrderStatus) {
        TaiTouListFragment orderListFragment = new TaiTouListFragment();
        orderListFragment.setOrderStatus(iOrderStatus);

        return orderListFragment;
    }

    public TaiTouListFragment setOrderStatus(HeTongIOrderStatus iOrderStatus) {
        mIOrderStatus = iOrderStatus;
        return this;
    }

    public TaiTouListFragment setSearchKey(String searchKey) {
        mSearchKey = searchKey;
        return this;
    }

    public TaiTouListFragment setWitch(String witch) {
        mYinCangWitch = witch;
        return this;
    }


    @Override
    protected ContractListContract.View createView() {
        huRequest = new HuRequest();
        return this;
    }

    @Override
    protected ContractListContract.Presenter createPresenter() {
        return new TaiTouPresenter(getContext());
    }


    @Override
    public RecyclerArrayAdapter createAdapter() {
//        return new ShenContractListAdapter(getContext(), mIOrderStatus,mYinCangWitch);
        return new TaiTouListAdapter(getContext(),2);
    }

    @Override
    protected void initListener() {

        mAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(int position) {

//                List<FuJianListBean.RecordsDTO> list =mAdapter.getAllData();
//                String code = list.get(position).getCode();
//                deleteDiaLog(position,code);

            }
        });

//        mAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
//            @Override
//            public void onItemChildClick(View view, int position) {
////                List<FuJianListBean.RecordsDTO> list =mAdapter.getAllData();
////                String code = list.get(position).getCode();
////                deleteDiaLog(position,code);
//
//
////                switch (view.getId()){
////                    case R.id.tv_xiugai:
////                        goQuotationDetail(position);
////                        break;
////                    case R.id.tv_shanchu:
////                        deleteDiaLog(position);
////
////                        break;
////                }
//            }
//        });

    }




    @Override
    public void requestDataList(int page, boolean isDialog) {
        if (mIOrderStatus != null) {
            OrderCondition orderCondition = new OrderCondition();
            orderCondition.page = page;
            orderCondition.searchKey = mSearchKey;
            getPresenter().requestOrderList(mIOrderStatus.getOrderListObservable(orderCondition), isDialog,huRequest,page);
        }
    }

    @Override
    public void initData() {


        fragment_contract_list_addContractButton.setVisibility(View.GONE);
        ll_search_body.setVisibility(View.GONE);
    }

    @Override
    protected void requestSearch(String searchKey) {
        mSearchKey = searchKey;
        refreshData(true);
    }

    @Override
    public void onEvent(CommonEvent event) {
        super.onEvent(event);
        switch (EventWhat.valueOf(event.getWhat())) {
            case EVENT_REFRESH_TAITOU_LIST:
//                if (isHasLoadData())
                    refreshData(false);
                break;

        }
    }











}
